/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhou.common.mybatis.template.shiro.api;

import com.google.common.collect.Lists;
import com.zhou.common.mybatis.template.shiro.dto.Group;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/idm")
public class ApiGroupsResource {

    private List<Group> list= Lists.newArrayList(
            new Group("group1","group1","group1"),
            new Group("group2","group2","group2"),
            new Group("group3","group3","group3"),
            new Group("group4","group4","group4")
    );


    @GetMapping(value = "/groups/{groupId}", produces = {"application/json"})
    public Group getGroupInformation(@PathVariable String groupId) {
        Map<String, Group> collect = list.stream().collect(Collectors.toMap(Group::getId, t -> t));
        return collect.get(groupId);
    }

    @GetMapping(value = "/groups", produces = {"application/json"})
    public List<Group> findGroupsByFilter(@RequestParam("filter") String filter) {
        return list;
    }

}
